package com.dfbz.TCP;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
            //创建一个客户端
            Socket client = new Socket("127.0.0.1", 8888);
            //从服务端接受信息
            InputStream inputStream = client.getInputStream();
            //从服务端写信息
            OutputStream outputStream = client.getOutputStream();
            //写信息
            String s = new Scanner(System.in).nextLine();
            if (s != null) {
                outputStream.write(s.getBytes());
            }
            byte[] data = new byte[1024];
            int len = inputStream.read(data);
            System.out.println("服务端:" + new String(data, 0, len));
//        outputStream.flush();
        }
    }

